home *** CD-ROM | disk | FTP | other *** search
- /* simacid.c
- *
- * An After Dark module by Tristan Farnon, Robert George, and Harrison Page
- *
- * Melt - by Tristan Farnon (tristan@west.darkside.com)
- * Ripple - by Robert George (rgeorge@mv.us.adobe.com)
- * After Dark module and Bad - by Harrison Page (harrison@wiretap.spies.com)
- *
- * v1.0 – pop-up menu to select your trip (Melt, Ripple) added
- * checkbox "James is helping?" makes James' characteristic moaning sounds when enabled
- * module's credits box features James in all his glory
- * support for all screen sizes based on monitorRect
- *
- * v1.1 – removed all that extra garbage left over from Bouncing Ball
- * added another trip (Bad) that inverts rects some of the time
- * changed NUM_LOOPS from 500 to 350 - better abort response
- * James only moans 10% of the time now
- *
- * to do – support for multiple monitors - melt or blank the other one out?
- * James should make more noises
- * adjustable speed of [melting,ripple]
- * long pause to abort in Demo mode rather annoying
- */
-
- #include <QuickDraw.h>
- #include <Memory.h>
- #include <Resources.h>
- #include <OSUtils.h>
- #include <ToolUtils.h>
- #include <FixMath.h>
- #include <Picker.h>
-
- #include "GraphicsModule_Types.h"
- #include "Sounds.h"
- #include "simacid.h"
-
- OSErr DoInitialize (Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params)
- {
- OSErr result;
- short i;
- Handle h;
- AcidStoragePtr acidStorage;
- Rect monitorRect;
- StringPtr errorMessage = (StringPtr)"\pSimAcid failed – you got burned.";
-
- /* in case we have an error, this message will be displayed. */
- BlockMove(errorMessage, params->errorMessage, 1 + errorMessage[0]);
-
- h = NewHandleClear(sizeof(AcidStorage)); /* allocate handle to my storage */
- FailNIL(h);
-
- *storage = h; /* store a reference to our storage where After Dark™ can keep it. */
-
- MoveHHi(h); /* lock down our storage so we can refer to it by pointer. */
- HLock(h);
- acidStorage = (AcidStoragePtr)*h;
-
- /* see if a sound channel is even part of the parameter block. */
- acidStorage->soundAvailable = (params->systemConfig & SoundAvailable) != 0;
-
- if(acidStorage->soundAvailable)
- {
- /* load the resources for our sounds. */
-
- acidStorage->jamesSound = GetResource('snd ', JAMES_MOAN);
- FailNIL(acidStorage->jamesSound);
-
- /* get ready to use sound. */
- acidStorage->soundInfo = OpenSound();
- }
-
- /* unlock storage handle. */
- HUnlock(h);
-
- return noErr;
- }
-
- static void CleanUp (AcidStorage** storage)
- {
- if (storage)
- {
- AcidStorage *acidStorage;
-
- HLock ((Handle) storage);
- acidStorage = *storage;
-
- if (acidStorage->soundAvailable) /* free the sounds! */
- if (acidStorage->jamesSound)
- ReleaseResource (acidStorage->jamesSound);
-
- DisposHandle ((Handle) storage);
- }
- }
-
- OSErr DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
- {
- return noErr;
- }
-
- OSErr DoDrawFrame (Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
- {
- register AcidStoragePtr acidStorage; /* to hold dereferenced storage handle */
- Rect monitorRect; /* rectange of monitor */
- Rect rip; /* current rect */
- short scrollType; /* type of window scroll (see switch below) */
- short jamesRandom; /* to check whether james is helping this time */
- int howOften;
- int controlJamesEnabled; /* whether james is helping via AD panel */
- int controlTripType; /* what kind of trip we're on */
- int j;
- int count;
- int moveHere = 2; /* generic values */
- int moveThere = -2;
- int howBad = 50; /* how often to invert a rect */
-
- HLock(storage);
- acidStorage = (AcidStoragePtr) *storage;
-
- monitorRect = params->monitors->monitorList[0].bounds;
- controlTripType = params->controlValues[0]; /* 0 = pop-up for type of trip */
- controlJamesEnabled = params->controlValues[1]; /* 1 = whether james is helping */
-
- howOften = JAMES_RARELY; /* for testing purposes */
- jamesRandom = RangedRdm(1, JAMES_ZENITH); /* pick a random number */
-
- /* if howOften is greater than the random number between 1 and 1000, moan. */
-
- if (controlJamesEnabled)
- if ((jamesRandom > howOften) && (acidStorage->soundAvailable))
- PlaySound (acidStorage->soundInfo, params->sndChannel, acidStorage->jamesSound);
-
- for (j = 0, count = 0; j <= NUM_LOOPS; j++)
- {
- rip = ObtainRect (&monitorRect); // get a rectangle
-
- switch (controlTripType) // set up trip type */
- {
- case TRIP_MELTING:
- scrollType = 1; // tristan's melt - only move downward */
- break;
-
- case TRIP_RIPPLE:
- scrollType = RangedRdm(1, 5); // bob's ripple - move every which way */
- break;
-
- case TRIP_BAD:
- scrollType = RangedRdm(1, 5);
- moveHere = 10;
- moveThere = -10;
- howBad = 200;
- break;
- }
-
- switch (scrollType)
- {
- case 1:
- ScrollRect (&rip, 0, moveHere, nil);
- if (controlTripType == TRIP_BAD)
- ScrollRect (&rip, 0, moveThere, nil);
- break;
-
- case 2:
- ScrollRect (&rip, 0, moveThere, nil);
- if (controlTripType == TRIP_BAD)
- ScrollRect (&rip, 0, moveHere, nil);
- break;
-
- case 3:
- ScrollRect (&rip, moveHere, 0, nil);
- if (controlTripType == TRIP_BAD)
- ScrollRect (&rip, moveThere, 0, nil);
- break;
-
- case 4:
- ScrollRect (&rip, moveThere, 0, nil);
- if (controlTripType == TRIP_BAD)
- ScrollRect (&rip, moveHere, 0, nil);
- break;
- }
-
- if (!(++count % howBad))
- if (controlTripType == TRIP_BAD)
- InvertRect (&rip);
- }
-
- HUnlock(storage);
-
- return noErr;
- }
-
- OSErr DoClose (storage, blankRgn, params)
- Handle storage;
- RgnHandle blankRgn;
- GMParamBlockPtr params;
- {
- AcidStorage **acidStorage = (AcidStorage**) storage;
-
- if(acidStorage)
- CloseSound((**acidStorage).soundInfo, params->sndChannel);
-
- /* deallocate our storage */
- CleanUp(acidStorage);
-
- return noErr;
- }
-
- OSErr DoSetUp(blankRgn, message, params)
- RgnHandle blankRgn;
- short message;
- GMParamBlockPtr params;
- {
-
- switch(message)
- {
- default:
- SysBeep(1);
- break;
- }
- return noErr;
- }
-
- /* utility functions. */
-
- Rect ObtainRect (Rect *monitorRect)
- {
- static Rect SetUpRect;
-
- SetUpRect.top = RangedRdm (monitorRect->top, monitorRect->bottom);
- SetUpRect.left = RangedRdm (monitorRect->left, monitorRect->right);
- SetUpRect.bottom = RangedRdm (monitorRect->top, monitorRect->bottom);
- SetUpRect.right = RangedRdm (monitorRect->left, monitorRect->right);
-
- return (SetUpRect);
- }
-
-
- unsigned short RangedRdm( unsigned short min, unsigned short max )
- {
- unsigned qdRdm;
- long range, t;
-
- qdRdm = Random();
- range = max - min;
- t = (qdRdm * range) / 65536;
- return( t+min );
- }